home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Resources / Online / Term / Extras / Source / gtlayout-source.lha / LTP_NewMenu.c < prev    next >
C/C++ Source or Header  |  1996-03-18  |  4KB  |  195 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1996 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. #ifdef DO_MENUS
  15.  
  16.     /* LTP_NewMenu():
  17.      *
  18.      *    Create a new menu, based on the Screen and Font given.
  19.      */
  20.  
  21. RootMenu *
  22. LTP_NewMenu(struct Screen *Screen,struct TextAttr *TextAttr,struct Image *AmigaGlyph,struct Image *CheckGlyph,LONG *ErrorPtr)
  23. {
  24.     LONG Error;
  25.  
  26.     if(Screen)
  27.     {
  28.         APTR Pool;
  29.  
  30.             // Wrap all the allocations into a pool
  31.  
  32.         if(Pool = AsmCreatePool(MEMF_ANY | MEMF_PUBLIC | MEMF_CLEAR,1024,1024,SysBase))
  33.         {
  34.             struct RootMenu *Root;
  35.  
  36.                 // Create the root
  37.  
  38.             if(Root = (struct RootMenu *)AsmAllocPooled(Pool,sizeof(struct RootMenu),SysBase))
  39.             {
  40.                 Root->Pool = Pool;
  41.  
  42.                 if(TextAttr)
  43.                     Root->TextAttr = TextAttr;
  44.                 else
  45.                     Root->TextAttr = Screen->Font;
  46.  
  47.                     // Open the menu font
  48.  
  49.                 if(Root->Font = OpenFont(Root->TextAttr))
  50.                 {
  51.                         // Get the drawing information
  52.  
  53.                     if(Root->DrawInfo = GetScreenDrawInfo(Screen))
  54.                     {
  55.                             // Fill in the dummy rastport
  56.  
  57.                         InitRastPort(&Root->RPort);
  58.  
  59.                         Root->RPort.BitMap = Screen->RastPort.BitMap;
  60.  
  61.                         SetFont(&Root->RPort,Root->Font);
  62.  
  63.                                 // Get the text rendering pen
  64.  
  65.                         if(Root->DrawInfo->dri_Version < 2)
  66.                             Root->TextPen = Root->DrawInfo->dri_Pens[DETAILPEN];
  67.                         else
  68.                             Root->TextPen = Root->DrawInfo->dri_Pens[BARDETAILPEN];
  69.  
  70.                                 // Something to remember
  71.  
  72.                         Root->Screen = Screen;
  73.  
  74.                             // Let's hope it won't grow in the future
  75.  
  76.                         CopyMem(Root->TextAttr,&Root->BoldAttr,sizeof(struct TTextAttr));
  77.  
  78.                             // Make it boldface
  79.  
  80.                         Root->BoldAttr.tta_Style |= FSF_BOLD;
  81.  
  82.                             // Initialize the lists
  83.  
  84.                         NewList((struct List *)&Root->MenuList);
  85.                         NewList((struct List *)&Root->ItemList);
  86.  
  87.                             // Get the glyph widths
  88.  
  89.                         if(CheckGlyph)
  90.                         {
  91.                             GetAttr(IA_Width,    CheckGlyph,&Root->CheckWidth);
  92.                             GetAttr(IA_Height,    CheckGlyph,&Root->CheckHeight);
  93.                         }
  94.                         else
  95.                         {
  96.                                 // No glyph is provided, use the default values
  97.  
  98.                             if(V39)
  99.                             {
  100.                                 struct Image *Glyph;
  101.  
  102.                                 if(Glyph = NewObject(NULL,SYSICLASS,
  103.                                     SYSIA_DrawInfo,         Root->DrawInfo,
  104.                                     SYSIA_Which,            MENUCHECK,
  105.                                     SYSIA_ReferenceFont,    Root->Font,
  106.                                 TAG_DONE))
  107.                                 {
  108.                                     GetAttr(IA_Width,    Glyph,&Root->CheckWidth);
  109.                                     GetAttr(IA_Height,    Glyph,&Root->CheckHeight);
  110.  
  111.                                     DisposeObject(Glyph);
  112.                                 }
  113.                             }
  114.  
  115.                             if(!Root->CheckWidth)
  116.                                 Root->CheckWidth = 15;
  117.  
  118.                             if(!Root->CheckHeight)
  119.                                 Root->CheckHeight = 8;
  120.                         }
  121.  
  122.                         if(AmigaGlyph)
  123.                         {
  124.                             GetAttr(IA_Width,    AmigaGlyph,&Root->AmigaWidth);
  125.                             GetAttr(IA_Height,    AmigaGlyph,&Root->AmigaHeight);
  126.                         }
  127.                         else
  128.                         {
  129.                                 // No glyph is provided, use the default values
  130.  
  131.                             if(V39)
  132.                             {
  133.                                 struct Image *Glyph;
  134.  
  135.                                 if(Glyph = NewObject(NULL,SYSICLASS,
  136.                                     SYSIA_DrawInfo,         Root->DrawInfo,
  137.                                     SYSIA_Which,            AMIGAKEY,
  138.                                     SYSIA_ReferenceFont,    Root->Font,
  139.                                 TAG_DONE))
  140.                                 {
  141.                                     GetAttr(IA_Width,    Glyph,&Root->AmigaWidth);
  142.                                     GetAttr(IA_Height,    Glyph,&Root->AmigaHeight);
  143.  
  144.                                     DisposeObject(Glyph);
  145.                                 }
  146.                             }
  147.  
  148.                             if(!Root->AmigaWidth)
  149.                                 Root->AmigaWidth = 23;
  150.  
  151.                             if(!Root->AmigaHeight)
  152.                                 Root->AmigaHeight = 8;
  153.                         }
  154.  
  155.                             // Establish default menu item height
  156.  
  157.                         Root->ItemHeight = Root->RPort.TxHeight;
  158.  
  159.                         if(Root->CheckHeight > Root->ItemHeight)
  160.                             Root->ItemHeight = Root->CheckHeight;
  161.  
  162.                         if(Root->AmigaHeight > Root->ItemHeight)
  163.                             Root->ItemHeight = Root->AmigaHeight;
  164.  
  165.                         Root->ItemHeight += 2;
  166.  
  167.                         return(Root);
  168.                     }
  169.                     else
  170.                         Error = ERROR_NO_FREE_STORE;
  171.  
  172.                     CloseFont(Root->Font);
  173.                 }
  174.                 else
  175.                     Error = ERROR_OBJECT_NOT_FOUND;
  176.             }
  177.             else
  178.                 Error = ERROR_NO_FREE_STORE;
  179.  
  180.             AsmDeletePool(Pool,SysBase);
  181.         }
  182.         else
  183.             Error = ERROR_NO_FREE_STORE;
  184.     }
  185.     else
  186.         Error = ERROR_REQUIRED_ARG_MISSING;
  187.  
  188.     if(ErrorPtr)
  189.         *ErrorPtr = Error;
  190.  
  191.     return(NULL);
  192. }
  193.  
  194. #endif    /* DO_MENUS */
  195.